const roleService = require('../service/roleService')
class RoleController {
  async getUserRole(ctx, next) {
    const { id } = ctx.params 
    const res = await roleService.getUserRole(id)
    ctx.body = {
      res:res[0]
    }
  }
  async getRoles(ctx, next) {
    const { pagenum, pagesize } = ctx.request.body
    const res = await roleService.getRoleList(pagenum, pagesize)
    ctx.body = {
      data: {
        pagenum,
        ...res
      },
      meta: {
        msg: '获取成功',
        status:200
      }
    }
  }
  async updateRole(ctx, next) {
    const { id } = ctx.params
    const { name, intro } = ctx.request.body
    await roleService.updateRole(id,name,intro)
    ctx.body = {
      meta: {
        msg:"success"
      }
    }
  }
  async removeRole(ctx, next) {
    const { id } = ctx.params 
    await roleService.removeRole(id)
    ctx.body = {
      meta: {
        msg:'success'
      }
    }
  }
}

module.exports = new RoleController()